home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1993 September / September 93.iso / Archives / Utilities / System / Startup / DumbIcon / DumbIcon.c < prev    next >
C/C++ Source or Header  |  1993-07-11  |  7KB  |  219 lines

  1. /* DumbIcon.c */
  2.  
  3. #include <Quickdraw.h>
  4. #include <Types.h>
  5. #include <OSUtils.h>
  6. #include <Resources.h>
  7. #include <Memory.h>
  8. #include <LoMem.h>
  9. #include <SetUpA4.h>
  10.  
  11.  
  12. /* Instructions for use:  Include a bunch of ICN# icon resources in the */
  13. /* file and they will get displayed.  If you want color, make a */
  14. /* 'cicn' color version of an already existing ICN# resource and give it */
  15. /* the same ID. */
  16.  
  17.  
  18. void Draw_Init_Icon (short icon_id);
  19.  
  20.  
  21. void                main(void)
  22.     {
  23.         short                            ResourceIndex;
  24.         Handle                        Resource;
  25.         Ptr                                MyInitPtr;
  26.         unsigned long            RanSeed;
  27.  
  28.         asm
  29.             {
  30.                 move.l        A0,MyInitPtr
  31.             }
  32.         RememberA0();
  33.         SetUpA4();
  34.         ResourceIndex = 1;
  35.         GetDateTime(&RanSeed);
  36.      LoopPoint:
  37.         Resource = Get1IndResource('ICN#',ResourceIndex);
  38.         if (Resource != (void*)0L)
  39.             {
  40.                 Str255            Name;
  41.                 short                ID;
  42.                 OSType            Type;
  43.                 long                Stupid;
  44.  
  45.                 GetResInfo(Resource,&ID,&Type,Name);
  46.                 Draw_Init_Icon(ID);
  47.                 ResourceIndex += 1;
  48.                 RanSeed = (RanSeed * 1103515245) + 12345;
  49.                 Delay((RanSeed & 127) + 30,&Stupid);
  50.                 goto LoopPoint;
  51.             }
  52.         RestoreA4();
  53.     }
  54.  
  55.  
  56. /******************************************************************************
  57.  
  58.     Draw_Init_Icon.c    1992 -- Chris Larson (cklarson@relleno.engr.ucdavis.edu)
  59.     
  60.     This function will draw an Init's icon on the screen during startup.
  61.     
  62.     Include the line,
  63.     
  64.         extern void Draw_Init_Icon (short icon_id);
  65.         
  66.     in your INIT source with your function prototypes and pass in the
  67.     resource ID of the icon you wish to be drawn. If color QD exists, the
  68.     function will attempt to draw a 'cicn' resource. If there is no color QD,
  69.     it will draw an 'icn#'. If an error occurs, SysBeep is called and nothing
  70.     is drawn.
  71.     
  72.     Based upon the method of Paul Mercer, Darin Adler, and Paul Snively from an
  73.         idea by Steve Capps.
  74.  
  75.     Code for compatablilty with IconWrap 1.2 based on similar code by Patrick
  76.         C. Beard, as modified by James W. Walker.
  77.  
  78. ******************************************************************************/
  79.  
  80. #define DI_INITIAL_OFFSET       8
  81. #define DI_BOTTOM_OFFSET        8
  82. #define DI_ICON_HEIGHT          32
  83. #define DI_ICON_WIDTH           32
  84. #define DI_ICON_OFFSET          8
  85. #define DI_NO_COLOR_QD          0x4000
  86. #define DI_BEEP_LENGTH          30
  87. #define DI_ICNPOUND_ROWBYTES    4
  88. #define DI_INCPOUND_MASK_OFFSET 128
  89. #define DI_CHECKSUM_CONSTANT    0x1021
  90. #define DI_PVT_GBL_SIZE         76
  91.  
  92. #define LEFT_OFFSET_POINTER     ((short *)0x092C) // Last 4 bytes of CurApName
  93. #define CHECKSUM_POINTER        ((short *)0x092E) // hold draw position and
  94.                                                   // checksum.
  95.  
  96. typedef struct
  97.     {
  98.     Byte        QD_Private_Global_Space[DI_PVT_GBL_SIZE];
  99.     long        randseed;
  100.     BitMap      screenBits;
  101.     Cursor      arrow;
  102.     Pattern     dkGray;
  103.     Pattern     ltGray;
  104.     Pattern     gray;
  105.     Pattern     black;
  106.     Pattern     white;
  107.     GrafPtr     thePort;
  108.     } QD_Variables;
  109.  
  110. void Draw_Init_Icon (short icon_id)
  111. {
  112.     CIconHandle     icon_handle = NULL;
  113.     short           usable_screen_width;
  114.     Rect            destination_rect;
  115.     Rect            source_rect;
  116.     BitMap          icon_bitmap;
  117.     BitMap          mask_bitmap;
  118.     GrafPort        local_port;
  119.     QD_Variables    my_vars;
  120.     long            our_a5;
  121.     long            old_a5;
  122.     long            old_CurrentA5;
  123.     
  124.     /* Prepare A5 for InitGraf call */
  125.     
  126.     asm 68000
  127.         {
  128.         move.l  CurrentA5,old_CurrentA5
  129.         move.l  a5,old_a5
  130.         lea     our_a5,a5
  131.         move.l  a5,CurrentA5
  132.         }
  133.     
  134.     /* InitGraf and open our GrafPort */
  135.     
  136.     InitGraf (&(my_vars.thePort));
  137.     OpenPort (&local_port);
  138.     
  139.     // Determine if position is valid. If not, set to initial value. If so, do
  140.     // nothing.
  141.     
  142.     if ((((*LEFT_OFFSET_POINTER)<<1)^DI_CHECKSUM_CONSTANT) != (*CHECKSUM_POINTER))
  143.         *LEFT_OFFSET_POINTER = DI_INITIAL_OFFSET;
  144.     
  145.     /* Compute destination Rect. */
  146.     
  147.     usable_screen_width = local_port.portRect.right - local_port.portRect.left;
  148.     usable_screen_width -= usable_screen_width % (DI_ICON_WIDTH + DI_ICON_OFFSET);
  149.     
  150.     if (((local_port.portRect.left + *LEFT_OFFSET_POINTER)/usable_screen_width) !=
  151.             ((local_port.portRect.left + DI_ICON_WIDTH + *LEFT_OFFSET_POINTER)/usable_screen_width))
  152.         *LEFT_OFFSET_POINTER += DI_ICON_OFFSET + usable_screen_width -
  153.                 ((local_port.portRect.left + *LEFT_OFFSET_POINTER)%usable_screen_width);
  154.     
  155.     destination_rect.left = ((local_port.portRect.left + (*LEFT_OFFSET_POINTER)) % usable_screen_width);
  156.     destination_rect.top = local_port.portRect.bottom - ((DI_ICON_HEIGHT+DI_BOTTOM_OFFSET) * (1+(*LEFT_OFFSET_POINTER)/usable_screen_width));
  157.     destination_rect.bottom = destination_rect.top + DI_ICON_HEIGHT;
  158.     destination_rect.right = destination_rect.left + DI_ICON_WIDTH;
  159.     
  160.     /* If in color, use 'cicn'. If not, use 'ICN#'. SysBeep and return if resource unavailable. */
  161.     
  162.     if (!(ROM85&DI_NO_COLOR_QD))
  163.         {
  164.         icon_handle = GetCIcon (icon_id);
  165.         if (!icon_handle)
  166.             {
  167.             goto UseBWIcon; /* hack by Thomas R. Lawrence */
  168.             SysBeep (DI_BEEP_LENGTH);
  169.             return;
  170.             }
  171.         PlotCIcon (&destination_rect,icon_handle);
  172.         DisposCIcon (icon_handle);
  173.         }
  174.     else
  175.         {
  176.        UseBWIcon:
  177.         icon_handle = (CIconHandle)GetResource ('ICN#',icon_id);
  178.         if (!icon_handle)
  179.             {
  180.             SysBeep(DI_BEEP_LENGTH);
  181.             return;
  182.             }
  183.         
  184.         HLock ((Handle)icon_handle);
  185.         
  186.         /* Set source Rect and intialize source BitMaps. */
  187.         
  188.         SetRect (&source_rect,0,0,DI_ICON_HEIGHT,DI_ICON_WIDTH);
  189.         
  190.         icon_bitmap.bounds  = mask_bitmap.bounds = source_rect;
  191.         icon_bitmap.rowBytes = mask_bitmap.rowBytes = DI_ICNPOUND_ROWBYTES;
  192.         icon_bitmap.baseAddr = (Ptr)(*icon_handle);
  193.         mask_bitmap.baseAddr = (Ptr)(((Byte *)(*icon_handle))+DI_INCPOUND_MASK_OFFSET);
  194.         
  195.         /* Draw the 'ICN#' using its mask. */
  196.         
  197.         CopyMask (&icon_bitmap,&mask_bitmap,&(local_port.portBits),&source_rect,&source_rect,&destination_rect);
  198.         
  199.         HUnlock ((Handle)icon_handle);
  200.         ReleaseResource ((Handle)icon_handle);
  201.         }
  202.     
  203.     ClosePort (&local_port);
  204.     
  205.     /* Update drawing position and checksum. */
  206.     
  207.     *LEFT_OFFSET_POINTER += DI_ICON_WIDTH+DI_ICON_OFFSET;
  208.     
  209.     *CHECKSUM_POINTER = ((*LEFT_OFFSET_POINTER)<<1)^DI_CHECKSUM_CONSTANT;
  210.     
  211.     /* Reset A5 and CurrentA5 */
  212.     
  213.     asm 68000
  214.         {
  215.         movea.l old_a5,a5
  216.         move.l  old_CurrentA5,CurrentA5
  217.         }
  218. }
  219.